package com.example.service;

import java.util.ArrayList;
import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.example.Mapper.oderfromMapper;
import com.example.pojo.oderfrom;
import com.example.pojo.oderfromcong;
import com.example.vo.PageBean;

@Service
public class oderfrombiz
{
	@Autowired 
	oderfromMapper mapper;
	
	/**
	 * 分页查询
	 * @param page
	 * @return
	 */
	public PageBean querybypage(int pagenum,int pagesize)
	{	
		PageBean pb=new PageBean();
		pb.setPagenum(pagenum);
		pb.setPagesize(pagesize);
		pb.setRowcount(mapper.querycount());
		List<oderfrom> ins = new ArrayList<oderfrom>();
		for (oderfrom od : mapper.querybypage((pagenum-1)*pagesize,pagesize))
		{
			od.setOrder(mapper.querybypage1(od.getBillno()));
			ins.add(od);
		}
		pb.setPagedata(ins);
		return pb;
	}
	
	/**
	 * 通过id查询
	 * @param id
	 * @return
	 */
	public int querybyid(String id)
	{
		return mapper.querybyid(id);		 	
	}
	
	/**
	 * 新增
	 * @param in
	 */
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void addoder(oderfrom od)
	{
		if (mapper.querybyid(od.getBillno())<=0) {
			mapper.addoder(od);
			mapper.addoder1(od);
		}else{
			mapper.deleteodercong(od.getBillno());
			mapper.deleteoder(od.getBillno());
			mapper.addoder(od);
			mapper.addoder1(od);
		}
	}
	
	/**
	 * 修改审核状态
	 * @param in
	 */
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void updateshzt(String id)
	{
		mapper.updateshzt(id);
	}
	
	/**
	 * 修改反审核状态
	 * @param in
	 */
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void updateshzt1(String id)
	{
		mapper.updateshzt1(id);
	}
	/**
	 * 修改请购表的单况(审核)
	 * @param in
	 */
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void updateqgdk(String id)
	{
		mapper.updateqgdk(id);
	}
	
	/**
	 * 修改请购表的单况(反审核)
	 * @param in
	 */
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void updateqgcong(String id)
	{
		mapper.updateqgcong(id);
	}
	
	/**
	 * 删除表
	 * @param billno
	 */
	
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void deleteoder(String billno)
	{	
		mapper.deleteodercong(billno);//从
		mapper.deleteoder(billno);//主
	}
}
